﻿using Newtonsoft.Json;
using System;
using System.IO;
using System.Net;

namespace ybx_caller.entity
{
    public  class ShareData
    {
        public Head head { set; get; }
        public class Head
        { 
            public string charset { set; get; }
            public string app_id { set; get; }
            public string resource_code { set; get; }
            public string encrypt_type { set; get; }
            public string enterprise_id { set; get; }
            public string language { set; get; }
            public string method { set; get; }
            public string sys_track_code { set; get; }
            public string timestamp { set; get; }
            public string version { set; get; }
        }

        public Body body { set; get; }
        public class Body
        {
            public string start_date { set; get; }
            public string end_date { set; get; }
        }

        //public static string getInput(string bdate,string edate) {
        //    long unixTimestamp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

        //    ShareData data = new ShareData();
        //    ShareData.Head head = new ShareData.Head();
        //    head.charset = "utf-8";
        //    head.app_id = "885c939b59df4804913c5643d9dc99b2";
        //    head.resource_code = "";
        //    head.encrypt_type = "AES";
        //    head.enterprise_id = "SYSTHYY";
        //    head.language = "zh_CN";
        //    head.method = "orgine.powermrrp.service.api.recognition.queryQuotationRecord";
        //    head.sys_track_code = "1593310344149";
        //    head.timestamp = unixTimestamp.ToString();
        //    head.version = "1.0";

        //    ShareData.Body body = new ShareData.Body();
        //    body.start_date = bdate;
        //    body.end_date = edate;

        //    data.head = head;
        //    data.body = body;
        //    return JsonConvert.SerializeObject(data);
        //}

        //public static string sendMsg(string data)
        //{
        //    string url = "http://192.168.128.85:28803/registerReport";
        //    string response = SendPostRequest(url, data);
        //    return response;
        //}

        //private static string SendPostRequest(string url, string jsonData)
        //{
        //    var request = (HttpWebRequest)WebRequest.Create(url);
        //    request.Method = "POST";
        //    request.ContentType = "application/json";
        //    request.Accept = "application/json";
        //    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        //    {
        //        streamWriter.Write(jsonData);
        //        streamWriter.Flush();
        //    }
        //    try
        //    {
        //        var response = (HttpWebResponse)request.GetResponse();
        //        using (var streamReader = new StreamReader(response.GetResponseStream()))
        //        {
        //            string result = streamReader.ReadToEnd();
        //            return result;
        //        }
        //    }
        //    catch (WebException ex)
        //    {
        //        using (var streamReader = new StreamReader(ex.Response.GetResponseStream()))
        //        {
        //            string errorResponse = streamReader.ReadToEnd();
        //            return "请求失败: " + errorResponse;
        //        }
        //    }
        //}
    }
}
